<?php
/**
 * @author		C. Hazekamp
 * @copyright	C. Hazekamp
 * @version     2.0.0
 * @date   		2011-11-28
 * @access		public
 * @filesource	none
 * @package     ObbyCMS 2.0
 */

/************************
*	Start a new session for some basic stuff
************************/
session_start();

/************************
*	Basis error reporting
************************/
error_reporting(E_ALL);

/************************
* 	OB Start is used to hold any output from being printed.
*	This way, all variables can be passed to the templates
*	without any disturbance, while this will make rendering
*	a little faster.
************************/
ob_start();

/************************
*	Validation check for included files.
*	This makes sure this files cannot
*	be opened on a seperate page
************************/
define('PUBLIC_HTML', true);

/***********************
*	The core file is the most important file
*	of the whole system. All other
*	important files are included here.
*	The core variables, functions, classes, etc
*	are all initiated in this file
***********************/
require('core.php');

/***********************
*	This function initiates the user session.
*	It checks for either an existing session
*	or an existing cookie. If one of these exist,
*	the function will validate this with the database
*	and create the login section if this one is true.
*	If false, or with no exisiting session at all,
*	the user will travel the site as a guest.
*	In all cases, IP and Browser information
*	are registered for statistical reasons.
************************/
$user->set_session();

/***********************
*	Count the amount of parts
*	in the URI, preparing it
*	for content use.
************************/
$x_params = count($url_params);

/***********************
*	Set the page variable.
*	Uses the first url param
*	found after the main domain.
*	If there are no parameters
*	after the domain, page_var
*	will be set as home by default
************************/
$page_var = (!empty($url_params[$url_offset])) ? $url_params[$url_offset] : 'home';

/***********************
*	Checks the cache for
*	the current page.
*	if a valid cached page
*	is found, that file
*	will be loaded.
*	Else, everything will
*	be generated from scratch
*	by the content class.
************************/
$cache->set($page_var);

/*if ($cache->is_cached())
{
	$cache->load($page_var);
}
else
{*/
	$page = $content->get_page($page_var);
	
	$get_menu = $db->sql_query("SELECT * FROM ".TABLE_MENU);
	while ($row_menu = $db->sql_fetch_assoc($get_menu))
	{
		//print_r($row_menu);
		$tpl->zone('menu', array(
			'TITLE'		=> $row_menu['men_title'],
			'LINK'		=> $row_menu['men_link'],
			'TARGET'	=> $row_menu['men_target']
		));
	}

	switch ($page['page_type'])
	{
		/**
		 * Get Simple Page
		 */
		case PAGE_SIMPLE:
			$tpl->set_vars('TITLE', $page['pct_title']);
			$tpl->set_vars('CONTENT', $string->text($page['pct_content']));
			$cache->save($tpl->output('output/cfh/simple_body', $content->tpl_vars));
		break;
		
		/**
		 * Get an advanced page
		 * build up with modules
		 */
		case PAGE_CUSTOM:
			foreach ($content->get_parts($page['page_id']) as $part)
			{
				switch ($part['type'])
				{
					case 'module':
						include(PATH_MODULES . $part['module'] . '/' . $part['module_part'] . EXT_PHP);
					break;
					
					case 'media':
						$myhump = '';
					break;
				}
				$tpl->zone("structure", array(
					'TITLE'		=> $part['title'],
					'CONTENT'	=> $part['content'],
					'TEMPLATE'	=> $part['template']
				), $part['template']);
				
				$cache->save($tpl->output('output/cfh/main_body', $content->tpl_vars));
			}
		break;
		
		/**
		 * Get a full html file
		 */
		case PAGE_HTML:
			$cache->save($tpl->output('custom/html/' . $page['page_file'], $content->tpl_vars));
		break;
		
		/**
		 * Get a full php file
		 */
		case PAGE_PHP:
			$tpl->set_vars('TITLE', $page['pct_title']);
			$tpl->set_vars('CONTENT', $string->text($page['pct_content']));
			include('custom/php/' . $page['page_file']);
		break;
		
		default:
			echo 'nee toch?';
		break;
	}
//}

// End of File
?>